#!/bin/bash
source /root/anaconda3/bin/activate py39
cd /home/data/wwwroot/gusto/scripts

# 数据库配置
DB_HOST="127.0.0.1"
DB_USER="sto"
DB_PASS="Sto@2025"
DB_NAME="sto"
TODAY=`date +%Y-%m-%d`

# 查询语句
QUERY="SELECT COUNT(*) FROM day_kline WHERE trade_date='$TODAY';"

# 执行查询并获取结果
RESULT=$(mysql -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME -e "$QUERY" -s -r)

# 判断结果
if [ $RESULT -gt 0 ]; then
    echo "数据库有记录。"
    # 查询语句
    QUERY1="SELECT COUNT(*) FROM day_kline_0 WHERE trade_date='$TODAY';"

    # 执行查询并获取结果
    RESULT1=$(mysql -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME -e "$QUERY1" -s -r)

    if [ $RESULT1 -gt 0 ]; then
        echo "数据记录已拆分"
    else
        source /home/data/wwwroot/centerdata/scripts/task1_exe.sh
        source /home/data/wwwroot/centerdata/scripts/task2_exe.sh
        source /home/data/wwwroot/centerdata/scripts/task9_exe.sh
        source /home/data/wwwroot/centerdata/scripts/task11_exe.sh
        source /home/data/wwwroot/gusto/run23.sh
        python3 send_sto_msg.py "{$TODAY}今日数据处理数据已完成"
        python3 getAllScore.py
        python3 calc_score.py
        python3 getCodeInfo.py
    fi
else
    echo "数据库无记录。"
    source /root/work/act.sh
    python3 send_sto_msg.py "{$TODAY}今日数据已存储"
fi
